package arithmetic.baseAlgorithm.sort;

/**
 * 冒泡排序
 *
 * @author zhangyanqi
 * @since 1.0 2017/12/31
 */
public class BubbleSort {

    public static void sort(int[] toSort) {
        for (int i = 0; i < toSort.length; i++) {
            for (int j = 0; j < toSort.length - i - 1; j++) {
                if (toSort[j] > toSort[j + 1]) {
                    int temp;
                    temp = toSort[j];
                    toSort[j] = toSort[j + 1];
                    toSort[j + 1] = temp;
                }
            }
        }

    }

    public static void main(String[] args) {
        int[] ints = {3, 2, 1, 5, 7, 6};
        sort(ints);
        System.out.println(ints[0] + " " + ints[1] + " " + ints[2] + " " + ints[3] + " " + ints[4] + " " + ints[5]);
    }
}
